import axios from 'axios'
import * as Type from './types'

const changeHomeData = (result) => ({
  type: Type.CHANGE_HOME_DATA,
  articleList: result.articleList,
  recommendList: result.recommendList,
  topicList: result.topicList
})

export const getHomeInfo = () => {
  return (dispatch) => {
    axios.get('/api/home.json').then( res => {
      const result = res.data.data;
      dispatch(changeHomeData(result))
    })
  }
}
const addHomeList = (list) => ({
  type: Type.ADD_HOME_LIST,
  list: list
})

export const getMoreList = () => {
  return (dispatch) => {
    axios.get('/api/homeList.json').then((res) => {
      const result = res.data.data.articleList;
      dispatch(addHomeList(result))
    })
  }
}

export const toggleTopShow = (show) => ({
  type:Type.TOP_SHOW,
  show
})